<template>
  <div class="home">
    <el-container>
      <el-header>
        <div>
          <img
            src="https://ftp.bmp.ovh/imgs/2021/05/684c59686a76f389.jpg"
            alt=""
          />
          <span class="title">XX公司后台管理系统</span>
        </div>
        <el-button type="danger" @click="logout">退出按钮</el-button>
      </el-header>
      <el-container>
        <el-aside :width="isopen ? '200px' : '69px'">
          <!-- 切换按钮区域 -->
          <div class="toggleBtn" @click="switchmenu">
            <i :class="isopen ? 'el-icon-s-unfold' : 'el-icon-s-fold'"></i>
          </div>

          <!-- 左侧的菜单栏导航区域 -->
          <el-menu
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            :unique-opened="true"
            :router="true"
          >
            <!-- 一级菜单 -->
            <el-submenu
              :index="item.id + ''"
              v-for="item in menulist"
              :key="item.id"
            >
              <!-- 一级菜单的模板 -->
              <template slot="title">
                <!-- 菜单图标 -->
                <!-- <i class="el-icon-position"></i> -->
                <!-- <i :class="iconObj[item.id]"></i> -->
                 <i :class="iconObj2[item.name]"></i>
                <!-- 文本 -->
                <span>{{ item.name }}</span>
              </template>
              <!-- 一级菜单下面的二级菜单  -->
              <el-menu-item
                v-for="subitem in item.child"
                :key="subitem.id"
                :index="subitem.path"
              >
                <template slot="title">
                  <!-- 菜单图标 -->
                  <!-- <i class="el-icon-position"></i> -->
                    <i :class="iconObj2[subitem.name]"></i>
                  <!-- 文本 -->
                  <span>{{ subitem.name }}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  props: [],
  components: {},
  data() {
    return {
      loginObj: {
        username: "admin",
        password: "1234561111",
      },
      menulist: [],
      iconObj: {
        1: "iconfont icon-user",
        2: "iconfont icon-gengduo",
        3: "iconfont icon-shouye",
        4: "iconfont icon-yanzhengma1",
        5: "iconfont icon-shoucang",
        6: "iconfont icon-fenxiang1",
      },
       iconObj2:{
        '用户管理':'iconfont icon-Management',
        '员工管理':'iconfont icon-quanxianguanli',
        '商品管理':'iconfont icon-shangpinguanli',
        '订单管理':'iconfont icon-dingdanguanli',
        '数据统计':'iconfont icon-shujutongji',
        '用户列表':'iconfont icon-yonghuliebiao',
        '员工列表':'iconfont icon-role-list',
        '权限列表':'iconfont icon-permissions-list',
        '商品列表':'iconfont icon-shangpinliebiao',
        '分类参数':'iconfont icon-quanbu',
        '商品分类':'iconfont icon-fenleigongnengleimu',
      },
      isopen: true,
    };
  },
  //方法 函数写这里
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    async getmenus() {
      const res = await this.$http.get("/api/menu");
      console.log("res.data menu菜单栏数据", res.data);
      if (!res.status == "ok") return;
      this.menulist = res.data.data;
      console.log("this.mehulist", this.menulist);
    },
    switchmenu() {
      this.isopen = !this.isopen;
    },
  },
  //计算属性
  computed: {},
  //侦听器
  watch: {},
  //过滤器
  filters: {},
  //以下是生命周期
  //组件创建之前
  beforeCreate() {},
  //组件创建之后
  created() {
    this.getmenus();
  },
  //页面渲染之前
  beforeMount() {},
  //页面渲染之后
  mounted() {},
  //页面视图数据更新之前
  beforeUpdate() {},
  //页面视图数据更新之后
  updated() {},
  //页面销毁之前
  beforeDestroy() {},
  //页面销毁之后
  destroyed() {},
};
</script>


<style  lang='scss' scoped>
.title {
  color: white;
  font-size: 30px;
}
.el-container {
  height: 100vh;
}
.el-header {
  background-color: #0c212b;
  height: 80px !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-header div {
  display: flex;
  align-items: center;
}
.el-header img {
  width: 60px;
  height: 60px;
  padding-right: 6px;
}
.el-aside {
  background-color: #545c64;
}
.el-main {
  background-color: #e9eef3;
}

.el-menu {
  border-right: none;
}

.toggleBtn {
  line-height: 24px;
  color: aliceblue;
  text-align: left;
  font-size: 17px;
  padding-left: 10px;
  cursor: pointer;
  background-color: darkcyan;
}

.el-aside {
  transition: all 0.3s ease;
}
.iconfont {
  margin-right: 35px;
}
</style>